﻿using System;
using System.Collections.Generic;
using Micua.Utility;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Micua.Bootstrap.Elements;

namespace Micua.Bootstrap
{
    public class Bootstrap<TModel> : Micua.Utility.Abstract.ClearObjectMember
    {
        /// <summary>
        /// HtmlHelper
        /// </summary>
        public HtmlHelper<TModel> Html { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="helper"></param>
        public Bootstrap(HtmlHelper<TModel> helper)
        {
            this.Html = helper;
        }
        #region CSS

        #region Viewport元数据标签
        /// <summary>
        /// Viewport元数据标签
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public MvcHtmlString Viewport(string content)
        {
            TagBuilder meta = new TagBuilder("meta");
            meta.Attributes.Add("name", "viewport");
            meta.Attributes.Add("content", content);
            return MvcHtmlString.Create(meta.ToString(TagRenderMode.SelfClosing));
        }
        /// <summary>
        /// Viewport元数据标签
        /// </summary>
        /// <param name="contents"></param>
        /// <returns></returns>
        public MvcHtmlString Viewport(object contents)
        {
            return Viewport(contents.ToDictionary('-'));
        }
        /// <summary>
        /// Viewport元数据标签
        /// </summary>
        /// <param name="contents"></param>
        /// <returns></returns>
        public MvcHtmlString Viewport(IDictionary<string, object> contents)
        {
            TagBuilder meta = new TagBuilder("meta");
            meta.Attributes.Add("name", "viewport");
            if (contents != null)
            {
                meta.MergeAttributes(contents);
            }
            return MvcHtmlString.Create(meta.ToString(TagRenderMode.SelfClosing));
        }
        #endregion

        #region 响应式图片
        public MvcHtmlString ResponsiveImage(string src)
        {
            return ResponsiveImage(src, null);
        }
        public MvcHtmlString ResponsiveImage(string src, object htmlAttributes)
        {
            return ResponsiveImage(src, htmlAttributes.ToDictionary('-'));
        }
        public MvcHtmlString ResponsiveImage(string src, IDictionary<string, object> htmlAttributes)
        {
            TagBuilder img = new TagBuilder("img");
            img.AddCssClass("img-responsive");
            img.Attributes.Add("src", src);
            if (htmlAttributes != null)
            {
                img.MergeAttributes(htmlAttributes);
                //foreach (var item in htmlAttributes)
                //{
                //    meta.Attributes.Add(item.Key, item.Value.ToString());
                //}
            }
            return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));
        }

        #endregion

        #region Container
        public HtmlElement Container()
        {
            return Container(null);
        }
        public HtmlElement Container(object htmlAttributes)
        {
            return Container(htmlAttributes);
        }
        public HtmlElement Container(IDictionary<string,object> htmlAttributes)
        {
            var tag = new HtmlElement(Html, "div");
            tag.AddHtmlAttribute("class", "container");
            tag.AddHtmlAttribute(htmlAttributes);
            Html.ViewContext.Writer.Write(tag.ToHtmlString());
            return tag;
        }
        #endregion

        #endregion
    }
}
